//
//  Auction_Main_Tbv_WX.m
//  ZITHER
//
//  Created by weixin on 2019/5/31.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Auction_Main_Tbv_WX.h"
#import "Auction_MainHead_TbvCell_WX.h"
#import "Auction_MainColumn_TbvCell_WX.h"
#import "Auction_performanceSpecial_TbvCell_WX.h"
#import "Auction_SpecialSaleList_VC_WX.h"
#import "specialSaleStatusModel.h"


@interface Auction_Main_Tbv_WX ()
@property (nonatomic,strong)specialSaleStatusModel * model;
@end
@implementation Auction_Main_Tbv_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self def];
        [self setUI];
        [self Starefreshing];
    }
    return self;
}

-(void)Starefreshing{
    [[serviceDefualt loadspecialSaleStatus:@"enable" reponseObjctClass:[specialSaleStatusModel class]]subscribeNext:^(ResponseData * x) {
        if (x.success) {
            self.model = x.responseData;
            [self reloadData];
        }else{
            [Tools showTips:x.errorInfo];
        }
        [self endRefreshing];
    }];
}

-(void)def{
    self.backgroundColor = HexColor(0xeeeeee);
    self.delegate = self;
    self.dataSource = self;
    
}

-(void)setUI{
    
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"indexPath == %@",indexPath);
    if (indexPath.row != 0) {
        specialSaleStatusSubModel *model = self.model.data[indexPath.row-1];
        Auction_SpecialSaleList_VC_WX *vc = [[Auction_SpecialSaleList_VC_WX alloc]init];
        vc.id = model.annotation.currentSceneId;
        vc.NavTtitle = model.name;
        [self.getNav pushViewController:vc animated:YES];
    }

}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.model.data.count+1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    

    if (indexPath.row ==0) {
        return [self getAuction_MainHead_TbvCell_WX:indexPath];
    }else{
        specialSaleStatusSubModel *model = self.model.data[indexPath.row-1];
        if ([model.annotation.remainingTime isEqualToString:@"0"]) {
            //暂停拍卖
            return [self getAuction_performanceSpecial_TbvCell_WX:indexPath];

        }else{
            //正在拍卖
            return [self getAuction_MainColumn_TbvCell_WX:indexPath];

        }
    
    }
    
}
-(UITableViewCell *)getAuction_MainHead_TbvCell_WX:(NSIndexPath *)indexPath{
    static NSString *sectionCell = @"Auction_MainHead_TbvCell_WX";
    Auction_MainHead_TbvCell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[Auction_MainHead_TbvCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
-(UITableViewCell *)getAuction_MainColumn_TbvCell_WX:(NSIndexPath *)indexPath{
    static NSString *sectionCell = @"Auction_MainColumn_TbvCell_WX";
    Auction_MainColumn_TbvCell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[Auction_MainColumn_TbvCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    specialSaleStatusSubModel *model = self.model.data[indexPath.row-1];
    cell.modelSub = model;
    return cell;
}

-(UITableViewCell *)getAuction_performanceSpecial_TbvCell_WX:(NSIndexPath *)indexPath{
    static NSString *sectionCell = @"Auction_performanceSpecial_TbvCell_WX";
    Auction_performanceSpecial_TbvCell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[Auction_performanceSpecial_TbvCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    specialSaleStatusSubModel *model = self.model.data[indexPath.row-1];
    cell.modelSub = model;
    return cell;
}


@end
